package jdbc;

import java.sql.Connection;

import mytool.Time;

import org.apache.commons.dbcp.BasicDataSource;

public class PoolTest {
	public static void main(String[] args) throws Exception {
		test();
	}

	private static void test() throws Exception{
		Configuration cfg = Configuration.configure();
		BasicDataSource ds = new BasicDataSource();
		ds.setUrl(cfg.getUrl());
		ds.setDriverClassName(cfg.getDriver());
		ds.setUsername(cfg.getUsername());
		ds.setPassword(cfg.getPwd());
		
		ds.setInitialSize(2);
		ds.setMaxActive(5);
		ds.setMaxIdle(2);
		ds.setMaxWait(5*60*1000);
		ds.setValidationQuery("select sysdate from dual");
		
		Time.start();
		for(int i=0;i<10;i++){
			Connection con=ds.getConnection();//得到的是对oracle连接封装的对象，先建出初始数目连接
//		System.out.println(con.getClass());
			con.close();//不是断开，而是归还连接
		}
		Time.end();
	}
}
